import time
import serial

# configure the serial connections (the parameters differs on the device you are connecting to)
ser = serial.Serial(0, 19200, timeout=1)
#	port='/dev/tty0',
#	baudrate=19200,
#	parity=serial.PARITY_EVEN,
#	stopbits=serial.STOPBITS_TWO,
#	bytesize=serial.EIGHTBITS
#)

ser.open()
ser.isOpen()
print ser.portstr
ser.flushInput()
ser.flushOutput()
ser.write(chr(0xFD))
time.sleep(5)
ser.write(chr(0xFC))

print 'Enter your commands below.\r\nInsert "exit" to leave the application.'

input=1
while 1 :
	# get keyboard input
	input = raw_input(">> ")
	if input == 'exit':
		ser.close()
		exit()
	else:
		# send the character to the device
		# (note that I append a \r\n carriage return and line feed to the characters - this is requested by my device)
		ser.write(input + '\r')
		out = ''
		# let's wait one second before reading output (let's give device time to answer)
		time.sleep(2)
		while ser.inWaiting() > 0:
			print 'yep'
			out += ser.read(8)
			
		if out != '':
			print ">>" + out
